package cn.gjculture.shopping.api.service.impl;

import cn.gjculture.shopping.api.dao.CommonDeleteMapper;
import cn.gjculture.shopping.api.dao.CommonUpdateMapper;
import cn.gjculture.shopping.api.dao.RoleDao;
import cn.gjculture.shopping.api.entity.Role;
import cn.gjculture.shopping.api.service.RoleService;
import cn.gjculture.shopping.api.util.DateUtil;
import cn.gjculture.shopping.api.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    RoleDao roleDao;

    @Autowired
    CommonDeleteMapper commonDeleteMapper;

    @Autowired
    CommonUpdateMapper commonUpdateMapper;

    @Override
    public int insert(Role role) {
        role.setRoleId(UUIDUtil.getUUID());
        role.setInsertTime(DateUtil.getTimestamp());
        role.setUpdateTime(DateUtil.getTimestamp());
        return roleDao.insert(role);
    }

    @Override
    public int update(Role role) {
        role.setUpdateTime(DateUtil.getTimestamp());
        return commonUpdateMapper.updateRole(role);
    }

    @Override
    public List<Role> query() {
        return roleDao.query();
    }

    @Override
    public Role queryById(String roleId) {
        return roleDao.queryById(roleId);
    }

    @Override
    public int delete(List<String> roleIds) {
        return commonDeleteMapper.deleteRole(roleIds);
    }
}
